/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ems_header_unpack.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"

#include <tibcoems/config.h>
#include <tibcoems/ems_core.h>
#include <tibcoems/ems_header.h>
#include <tibcoems/ems_comm.h>
#include <apmtest_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    char *p_bin = (char *) "00000b1c9955eeaa030000079916006b040200cb52b1470100260504514d000d393937303030393030303200043030000641434354000830303030303100003e05005ee7af3200000157f5e836f6362849443a454d532d3139392d373232362e354330383537394546463831423532423134373a343836003f020017000001030a446174615f6e616d65000926315f39393730303031303030305f39393730303039303030325f30335f3230313431303238000c526573656e645f666c61670009023000054461746500090932303136313032340009456e635f666c6167000902300009436f6d5f666c616700090230000e526563765f7379735f636f646500090c3939373030303230303030000b5265636f72645f6e756d0009023300094d73675f7479706500090232000e53656e645f7379735f636f646500090c3939373030303930303032000d4d73675f42617463685f6e6f00090830313236393331000b5265636f72645f6c656e00090532343439000554696d6500090730333130303300180000099489925b207b202243454e5f53455249414c5f4e4f223a20223036313030303231363431313735353432222c2022434c495f53455249414c5f4e4f223a20223036313030303231363431313735353432222c2022434c525f44415445223a20223230313431303238222c202242474e5f494e545f44415445223a20223230313431303238222c202254494d455f5354414d50223a20223230313631303234303333343536222c20225359535f434f4445223a20223939373030303930303032222c202254585f554e49545f434f4445223a20223631303030323136222c20224f50455241544f52223a20223230313630353231353831222c202254585f4e414d45434f4445223a20223031303130303031353838303030316230313130222c202254585f4348415241223a202230222c202254585f53544154455f434f4445223a20223030222c2022444143223a2022222c2022554e49545f414343545f47524f55505f4e4f223a20302c2022434153485f5553454d4f4445223a2022222c20225359535f53455249414c5f4e4f223a20223036313030303231363431313735353432222c202242474e5f54585f44415445223a20223230313431303238222c20224f55545359535f434f4445223a20223939373030303130303030222c2022494e5359535f434f4445223a20223939373030303930303032222c20224d45524348414e545f4d41524b223a2022222c20225445524d495f4d41524b223a2022222c202253484f505f54595045223a2022222c20224f52475f4a4e4c5f494e464f223a2022222c2022455854454e445f494e464f223a2022222c202254585f47524f5550515459223a20312c202254585f414d4f554e545f47524f5550223a205b207b2022414d545f54595045223a20223031222c202254585f414d54223a2031302e3030303030302c2022435552525f54595045223a2022313536222c2022524154455f41434354223a2022222c2022494e545f54585f414343545f535953434f4445223a2022222c2022524154455f494e5f41434354223a2022222c2022494e545f4d545f414343545f535953434f4445223a202222207d205d2c20224645455f47524f5550515459223a2030207d2c207b202243454e5f53455249414c5f4e4f223a20223036313030303231363431313739303132222c2022434c495f53455249414c5f4e4f223a20223036313030303231363431313739303132222c2022434c525f44415445223a20223230313431303238222c202242474e5f494e545f44415445223a20223230313431303238222c202254494d455f5354414d50223a20223230313631303234303333343536222c20225359535f434f4445223a20223939373030303930303032222c202254585f554e49545f434f4445223a20223631303030323136222c20224f50455241544f52223a20223230313630353231353031222c202254585f4e414d45434f4445223a20223031303130303031353838303030316230313130222c202254585f4348415241223a202230222c202254585f53544154455f434f4445223a20223030222c2022444143223a2022222c2022554e49545f414343545f47524f55505f4e4f223a20302c2022434153485f5553454d4f4445223a2022222c20225359535f53455249414c5f4e4f223a20223036313030303231363431313739303132222c202242474e5f54585f44415445223a20223230313431303238222c20224f55545359535f434f4445223a20223939373030303130303030222c2022494e5359535f434f4445223a20223939373030303930303032222c20224d45524348414e545f4d41524b223a2022222c20225445524d495f4d41524b223a2022222c202253484f505f54595045223a2022222c20224f52475f4a4e4c5f494e464f223a2022222c2022455854454e445f494e464f223a2022222c202254585f47524f5550515459223a20312c202254585f414d4f554e545f47524f5550223a205b207b2022414d545f54595045223a20223031222c202254585f414d54223a2031303030302e3030303030302c2022435552525f54595045223a2022313536222c2022524154455f41434354223a2022222c2022494e545f54585f414343545f535953434f4445223a2022222c2022524154455f494e5f41434354223a2022222c2022494e545f4d545f414343545f535953434f4445223a202222207d205d2c20224645455f47524f5550515459223a2030207d2c207b202243454e5f53455249414c5f4e4f223a20223036313030303231363431313737383832222c2022434c495f53455249414c5f4e4f223a20223036313030303231363431313737383832222c2022434c525f44415445223a20223230313431303238222c202242474e5f494e545f44415445223a20223230313431303238222c202254494d455f5354414d50223a20223230313631303234303333343536222c20225359535f434f4445223a20223939373030303930303032222c202254585f554e49545f434f4445223a20223631303030323136222c20224f50455241544f52223a20223230313630353231343931222c202254585f4e414d45434f4445223a20223031303130303031353838303030316230313130222c202254585f4348415241223a202230222c202254585f53544154455f434f4445223a20223030222c2022444143223a2022222c2022554e49545f414343545f47524f55505f4e4f223a20302c2022434153485f5553454d4f4445223a2022222c20225359535f53455249414c5f4e4f223a20223036313030303231363431313737383832222c202242474e5f54585f44415445223a20223230313431303238222c20224f55545359535f434f4445223a20223939373030303130303030222c2022494e5359535f434f4445223a20223939373030303930303032222c20224d45524348414e545f4d41524b223a2022222c20225445524d495f4d41524b223a2022222c202253484f505f54595045223a2022222c20224f52475f4a4e4c5f494e464f223a2022222c2022455854454e445f494e464f223a2022222c202254585f47524f5550515459223a20312c202254585f414d4f554e545f47524f5550223a205b207b2022414d545f54595045223a20223031222c202254585f414d54223a20333630302e3030303030302c2022435552525f54595045223a2022313536222c2022524154455f41434354223a2022222c2022494e545f54585f414343545f535953434f4445223a2022222c2022524154455f494e5f41434354223a2022222c2022494e545f4d545f414343545f535953434f4445223a202222207d205d2c20224645455f47524f5550515459223a2030207d205d00";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    Ems_header st_ems_header;
    memset(&st_ems_header, 0x00, sizeof(st_ems_header));

    CU_ASSERT_EQUAL(ems_header_unpack(arr_payload, strlen(p_bin) / 2, &st_ems_header), FR_SUCC);
    CU_ASSERT_EQUAL(st_ems_header.ui_header_len, 13);
    CU_ASSERT_EQUAL(st_ems_header.ui_pkt_len, 2844);
    CU_ASSERT_EQUAL(st_ems_header.pkt_type, EMS_PKT_TYPE_TEXT_MSG);
    CU_ASSERT_EQUAL(st_ems_header.model_type, EMS_MODEL_TYPE_UNKNOWN);
}

int add_suite_ems_header_unpack(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ems_header_unpack()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
